/******************************************************************************
* summary of number of non movers used to construct delta
*****************************************************************************/





*****************************************************************************
*** report number of movers and non movers 
*****************************************************************************
*** collapse data to cz level and merge with estimated place FE
use cz asofdate numobs $keyMvVars move_t num_mv *rel_q* varID delta_unpdcol_cust using "${dataRoot}/tu_mover_delta${ext}.dta", clear

cleanSample2WayFE


sum asofdate
tab num_mv if asofdate==`r(min)'

expand numobs

sum asofdate
tab num_mv if asofdate==`r(min)'

sum asofdate
keep if num_mv==1 & asofdate==`r(min)'
keep if min_rel_q<=-${evtQ} & max_rel_q>=${evtQ} & max_rel_q!=.	

*keep movers with matched non-movers 
keep if delta_unpdcol_cust!=.

tab num_mv



	

*****************************************************************************
*** number of non-movers observations by origin and destination Geos
*** run this for each level of delta, and combine the table afterwards
*** generate table A3
*****************************************************************************

use num_mv numobs ${Geo} ${deltaGeo} ${varL} asofdate move_t delta_ccdq_cust rel_q min_rel_q max_rel_q using "${dataRoot}/tu_mover_delta${ext}.dta", clear


*restrict to one observation per non-mover
tab num_mv
sum asofdate
keep if asofdate==`r(min)' | num_mv==1
	
	
*number of non-movers for each Geo
gen numobs_nmr = numobs if num_mv==0
bysort ${Geo} ${deltaGeo} : egen sum_nmvr = sum(numobs)

*keep movers
keep if num_mv==1 
	
*keep movers with matched non-movers so we can compute delta
keep if delta_ccdq_cust!=.

*keep move_t=0 and =-1 so pick up one observation for origin and one for destination
keep if inlist(rel_q, -1,0)


* movers with sufficient observations pre and post move
qui keep if min_rel_q<=-${evtQ} & max_rel_q>=${evtQ} & max_rel_q!=.	
		
*movers who moved prior to 2008
keep if move_t<200800
		
	
*expand to each mover to get weight right
expand numobs
tab rel_q
	
*sum stats
label var sum_nmvr "No. Non-Movers"
	
estpost sum  sum_nmvr, d
est store sst_delta
	
	
	
esttab sst_delta using "$outDir/Tex/sumstats_${Geo}_delta_numobs_mover${ext}_v1.tex", replace ///
			cells("mean(fmt(%9.0fc)) p1(fmt(%9.0fc)) p5(fmt(%9.0fc)) p10(fmt(%9.0fc)) p25(fmt(%9.0fc)) p50(fmt(%9.0fc)) p75(fmt(%9.0fc)) p90(fmt(%9.0fc)) p95(fmt(%9.0fc)) p99(fmt(%9.0fc))  ") ///
			collabels("Mean" "Pct 1" "Pct 5" "Pct 10" "Pct 25" "Pct 50" "Pct 75" "Pct 90" "Pct 95" "Pct 99") ///
			nonumber nomtitle noobs label scalars("N") sfmt(%20.0fc)


